package com.youhome.housing.controller;

import com.github.pagehelper.PageInfo;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.dto.DTOHousePropertySubType;
import com.youhome.service.dto.DTOHousePropertyType;
import com.youhome.service.dto.DTOState;
import com.youhome.service.model.HousePropertySubType;
import com.youhome.service.model.HousePropertyType;
import com.youhome.service.model.State;
import com.youhome.service.service.HouseCategoryService;
import com.youhome.service.service.HouseCommonService;
import com.youhome.service.service.HouseStatusService;
import com.youhome.utils.ModelMapperUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by chen365 on 2019/03/28.
 */
@RestController
@Api(tags = "公共属性", position = 4)
@RequestMapping(value = "/property")
public class PropertyController {

    @Autowired
    private HouseCommonService houseCommonService;
    @Autowired
    private HouseCategoryService houseCategoryService;
    @Autowired
    private HouseStatusService houseStatusService;

    @ApiOperation(value = "房屋一级类型", notes = "房屋一级类型", response = DTOHousePropertyType.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/type")
    public Object PropertyType() {
        List<HousePropertyType> list = houseCommonService.selectHousePropertyTypeAll();
        return new Result(ResultCode.SUCCESS, ModelMapperUtils.toList(list, new TypeToken<List<DTOHousePropertyType>>() {
        }.getType()));
    }

    @ApiOperation(value = "房屋二级类型", notes = "房屋二级类型", response = DTOHousePropertySubType.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/subtype")
    public Object propertySubType() {
        List<HousePropertySubType> list = houseCommonService.selectHousePropertySubTypeAll();
        return new Result(ResultCode.SUCCESS, ModelMapperUtils.toList(list, new TypeToken<List<DTOHousePropertySubType>>() {
        }.getType()));
    }

    @ApiOperation(value = "美国州", notes = "美国州",response = DTOState.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/states")
    public Object propertyState() {
        List<State> list = houseCommonService.selectStateAll();
        return new Result(ResultCode.SUCCESS, ModelMapperUtils.toList(list, new TypeToken<List<DTOState>>() {
        }.getType()));
    }

    @ApiOperation(value = "房源分类", notes = "房源分类", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/category")
    public Object propertyCategory() {
        return new Result(ResultCode.SUCCESS, houseCategoryService.selectByAll());
    }

    @ApiOperation(value = "房源状态", notes = "房源状态", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping(value = "/status")
    public Object propertyStatus() {
        return new Result(ResultCode.SUCCESS, houseStatusService.selectByAll());
    }
}
